﻿using SingleUserMall.Authorization.Users;
using SingleUserMall.Commissions;
using SingleUserMall.EntityFramework;
using SingleUserMall.Points;
using SingleUserMall.Sms;
using System.Linq;

namespace SingleUserMall.Migrations.SeedData
{
    class DefaultPointRulesCreator
    {
        private readonly SingleUserMallDbContext _context;

        public DefaultPointRulesCreator(SingleUserMallDbContext context)
        {
            _context = context;
        }

        public void Create()
        {
            CreateDefaultPointRules();
        }

        private void CreateDefaultPointRules()
        {
            User adminUser = _context.Users.FirstOrDefault(u => u.UserName == User.AdminUserName);
            if (adminUser != null)
            {
                //Default sms count
                var count = _context.PointRules.Count();
                if (count == 0)
                {
                    _context.PointRules.Add(new PointRules { UserRuleLevel = UserRuleLevel.NomalUser, SharePoint = 100, VIPGroupRate  = 0, DirectUserRate  = 0,DirectUserToVIP = 0, DirectUserToSuperVIP = 200 });
                    _context.PointRules.Add(new PointRules { UserRuleLevel = UserRuleLevel.VIPUser, SharePoint = 100, VIPGroupRate = 0, DirectUserRate = 0.25M, DirectUserToVIP = 100, DirectUserToSuperVIP = 200 });
                    _context.PointRules.Add(new PointRules { UserRuleLevel = UserRuleLevel.SuperVIPUser, SharePoint = 100, VIPGroupRate = 0.15M, DirectUserRate = 0.4M, DirectUserToVIP = 100, DirectUserToSuperVIP = 200 });
                }
                _context.SaveChanges();
            }
        }
    }
}
